﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace BankRemoteSystem.DAL
{
    class AccountAO
    {
        Connection con;
        List<SqlParameter> sqlpa;
        SqlParameter temp;
        public AccountAO()
        {
            con = new Connection();
        }
        public SqlDataReader getAccoutbyUserID(string userName)
        {
            string sql = "select * from [Account] where userID = '" + userName + "'";
            SqlCommand cmd = new SqlCommand(sql, con.getConnection());
            return cmd.ExecuteReader();
        }
        public bool updateBalance(string accountid, int balance)
        {
            sqlpa = new List<SqlParameter>();
            temp = new SqlParameter();
            string strSql = "spUpdateBalance";
            temp.ParameterName = "@accountID";
            temp.SqlDbType = SqlDbType.NVarChar;
            temp.Value = accountid;
            sqlpa.Add(temp);
            temp = new SqlParameter();
            temp.ParameterName = "@balance";
            temp.SqlDbType = SqlDbType.Int;
            temp.Value = balance;
            sqlpa.Add(temp);
            return con.MyExecuteNonQuery(strSql, CommandType.StoredProcedure, sqlpa);
        }
        public bool addBalance(string accountid, int balance)
        {
            sqlpa = new List<SqlParameter>();
            temp = new SqlParameter();
            string strSql = "spAddBalance";
            temp.ParameterName = "@accountID";
            temp.SqlDbType = SqlDbType.NVarChar;
            temp.Value = accountid;
            sqlpa.Add(temp);
            temp = new SqlParameter();
            temp.ParameterName = "@balance";
            temp.SqlDbType = SqlDbType.Int;
            temp.Value = balance;
            sqlpa.Add(temp);
            return con.MyExecuteNonQuery(strSql, CommandType.StoredProcedure, sqlpa);
        }

        public SqlDataReader getAccountbyID(string id)
        {
            sqlpa = new List<SqlParameter>();
            temp = new SqlParameter();
            string strSql = "spGetAccountByID";
            temp.ParameterName = "@accountID";
            temp.SqlDbType = SqlDbType.NVarChar;
            temp.Value = id;
            sqlpa.Add(temp);
            return con.executeQuery(strSql, CommandType.StoredProcedure, sqlpa);
        }
    }
}
